package controller;

import java.io.IOException;
import java.lang.*;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bizlogic.Manager;
import model.*;
import DAO.*;
import DAOMysql.*;
/**
 * Servlet implementation class DeleteFacility
 */
@WebServlet("/DeleteFacility")
public class DeleteFacility extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeleteFacility() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		deleteProcess(request,response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		deleteProcess(request,response);
	}
	private void deleteProcess(HttpServletRequest request,
			HttpServletResponse response) {
	//String username = request.getParameter("name");
		//System.out.println(request.getParameter("Id"));
	int	facilityID=Integer.parseInt(request.getParameter("facilityID"));
	//System.out.println(id);
	Manager m = new Manager();
	FacilitiesDTO f= m.findFacility(facilityID);
	System.out.println(f.toString());
//	  f.setFacilityID(id);
//    f=m.findFacility(id);
	m.delete(f);
	RequestDispatcher rd=request.getRequestDispatcher("/load");
	try {
		rd.forward(request, response);
	} catch (ServletException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

  }
}
